home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / beebe / h / dvifile < prev    next >
Encoding:
Text File  |  1990-05-19  |  5.2 KB  |  165 lines

  1. /* -*-C-*- dvifile.h */
  2. /*-->dvifile*/
  3. /**********************************************************************/
  4. /****************************** dvifile *******************************/
  5. /**********************************************************************/
  6.  
  7. void
  8. dvifile(argc,argv,filestr)
  9. int   argc;            /* argument count */
  10. char* argv[];            /* argument strings */
  11. char* filestr;            /* DVI filename to process */
  12. {
  13.  
  14. #define PAGENUMBER(p) ((p) < 0 ? (page_count + 1 + (p)) : (p))
  15.  
  16.     register INT16 i,j,m;    /* loop indices */
  17.     register INT16 swap;    /* swap storage */
  18.  
  19.     INT16 m_begin,m_end,m_step;    /* loop limits and increment */
  20.     INT16 list[3];        /* index list for sort */
  21.     char tempstr[MAXSTR];    /* temporary string storage */
  22.  
  23.  
  24.     /* small mod to allow full name to be given - help interface to
  25.        acorn wimp more easily */
  26.  
  27.     char *sp = filestr + strlen(filestr)-4;
  28.     if (strcmp(sp, ".dvi") == 0) *sp = '\0';
  29.  
  30.     /*
  31.     Establish the default  font file  search order.  This  is done  here
  32.     instead of  in  initglob()  or  option(),  because  both  could  set
  33.     fontlist[].
  34.  
  35.     By default, the search list contains  names for the PK, GF, and  PXL
  36.     font  files;  that  order   corresponds  to  increasing  size   (and
  37.     therefore, presumably, increasing  processing cost)  of font  raster
  38.     information.  This search  order may  be overridden at  run time  by
  39.     defining an alternate one in the environment variable FONTLIST;  the
  40.     order of  the  strings  "PK",  "GF",  and  "PXL"  in  that  variable
  41.     determines the search  order, and  letter case  is NOT  significant.
  42.     The  substrings  may  be  separated   by  zero  or  more   arbitrary
  43.     characters, so  the  values  "PK-GF-PXL", "PK  GF  PXL",  "PKGFPXL",
  44.     "PK;GF;PXL", "PK/GF/PXL"  are all  acceptable,  and all  choose  the
  45.     default search  order.   This  flexibility  in  separator  character
  46.     choice is occasioned  by the  requirement on some  systems that  the
  47.     environment variable have the syntax of a file name, or be a  single
  48.     "word".  If  any  substring  is  omitted, then  that  font  will  be
  49.     excluded from consideration.  Thus, "GF" permits the use only of  GF
  50.     font files.
  51.  
  52.     The indexes gf_index, pk_index, and pxl_index are in -1 .. 2, and at
  53.     least one must be non-negative.  A negative index excludes that font
  54.     file type from the search.
  55.     */
  56.  
  57.     /* Note that non-negative entries in list[] are UNIQUE. */
  58.     list[0] = gf_index = (INT16)strid2(fontlist,"GF");
  59.     list[1] = pk_index = (INT16)strid2(fontlist,"PK");
  60.     list[2] = pxl_index = (INT16)strid2(fontlist,"PXL");
  61.  
  62.     for (i = 0; i < 3; ++i)    /* put list in non-decreasing order */
  63.     for (j = i+1; j < 3; ++j)
  64.         if (list[i] > list[j])
  65.         {
  66.         swap = list[i];
  67.         list[i] = list[j];
  68.         list[j] = swap;
  69.         }
  70.     for (i = 0; i < 3; ++i)    /* assign indexes 0,1,2 */
  71.     if (list[i] >= 0)
  72.     {
  73.             if (list[i] == gf_index)
  74.         gf_index = i;
  75.             else if (list[i] == pk_index)
  76.         pk_index = i;
  77.             else if (list[i] == pxl_index)
  78.         pxl_index = i;
  79.     }
  80.  
  81.     if ((gf_index < 0) && (pk_index < 0) && (pxl_index < 0))
  82.     (void)fatal("dvifile():  FONTLIST does not define at least one of \
  83. GF, PK, or PXL fonts");
  84.  
  85.     (void)dviinit(filestr);    /* initialize DVI file processing */
  86.  
  87.     (void)devinit(argc,argv);    /* initialize device output */
  88.  
  89.     (void)readpost();
  90.     (void)FSEEK(dvifp, 14L, 0); /* position past preamble */
  91.     (void)getbytes(dvifp, tempstr,
  92.     (BYTE)nosignex(dvifp,(BYTE)1)); /* flush DVI comment */
  93.  
  94.     cur_page_number = 0;
  95.  
  96.  
  97. #if    (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2)
  98.     /* print pages in reverse order because of laser printer */
  99.     /* page stacking */
  100.     if (backwards)
  101.     {
  102.     m_begin = 1;
  103.     m_end = page_count;
  104.     m_step = 1;
  105.     }
  106.     else    /* normal device order */
  107.     {
  108.     m_begin = page_count;
  109.     m_end = 1;
  110.     m_step = -1;
  111.     }
  112.  
  113. #else
  114.   /* NOT (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2) */
  115.     /* print pages in forward order for most devices */
  116.     if (backwards)
  117.     {
  118.     m_begin = page_count;
  119.     m_end = 1;
  120.     m_step = -1;
  121.     }
  122.     else
  123.     {
  124.     m_begin = 1;
  125.     m_end = page_count;
  126.     m_step = 1;
  127.     }
  128. #endif /* (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2) */
  129.  
  130.     for (i = 0; i < npage; ++i)        /* make page numbers positive */
  131.     {                    /* and order pairs non-decreasing */
  132.     page_begin[i] = PAGENUMBER(page_begin[i]);
  133.     page_end[i] = PAGENUMBER(page_end[i]);
  134.     if (page_begin[i] > page_end[i])
  135.     {
  136.         swap = page_begin[i];
  137.         page_begin[i] = page_end[i];
  138.         page_end[i] = swap;
  139.     }
  140.     }
  141.  
  142.     for (m = m_begin; ; m += m_step)
  143.     {
  144.     for (i = 0; i < npage; ++i)    /* search page list */
  145.         if ( IN(page_begin[i],m,page_end[i]) &&
  146.             (((m - page_begin[i]) % page_step[i]) == 0) )
  147.         {
  148.         if (!quiet)        /* start progress report */
  149.             (void)fprintf(stderr,"[%d", m);
  150.         cur_page_number++;/* sequential page number 1..N */
  151.         cur_index = m-1;    /* remember index globally */
  152.         prtpage(page_ptr[cur_index]);
  153.         if (!quiet)        /* finish progress report */
  154.             (void)fprintf(stderr,"] ");
  155.         break;
  156.         }
  157.     if (m == m_end)            /* exit loop after last page */
  158.         break;
  159.     }
  160.  
  161.     (void)devterm();        /* terminate device output */
  162.  
  163.     (void)dviterm();        /* terminate DVI file processing */
  164. }
  165.